<template>
  <div ref="main">
    <p></p>
  </div>
</template>

<script>
import E from 'wangeditor'
export default {
  name: 'SummerWangEditor',

  data() {
    return {
      editor: '',
      text: ''
    }
  },

  mounted() {
    // 创建wangeditor实例
    this.editor = new E(this.$refs.main)
    // 自动取消焦点
    this.editor.config.focus = false
    // 配置菜单栏，删减菜单，调整顺序
    // this.editor.config.menus = ['bold', 'head', 'link', 'italic', 'underline']
    // 配置onchange回调函数
    this.editor.config.onchange = newHtml => {
      console.log('change之后最新的html', newHtml)
      // 把获取的富文本编辑的内容 --- 传递给弹框组件 --- 父组件
      this.$emit('sendEditor', newHtml)
      this.text = this.editor.txt.text()
    }
    // 配置触发onchange的时间频率，默认为200ms
    this.editor.config.onchangeTimeout = 500 //修改为500ms
    this.editor.create()
  },

  methods: {}
}
</script>

<style lang="scss" scoped></style>
